home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / PROLOG / HUMBOLT / HUMBOLTS / _files / _humboltsr / SYS._c < prev    next >
Text File  |  1990-06-10  |  4KB  |  188 lines

  1. /***************************************************
  2. ****************************************************
  3. **                                                **
  4. **  HU-Prolog     Portable Interpreter System     **
  5. **                                                **
  6. **  Release 1.62   January  1990                  **
  7. **                                                **
  8. **  Authors:      C.Horn, M.Dziadzka, M.Horn      **
  9. **                                                **
  10. **  (C) 1989      Humboldt-University             **
  11. **                Department of Mathematics       **
  12. **                GDR 1086 Berlin, P.O.Box 1297   **
  13. **                                                **
  14. ****************************************************
  15. ***************************************************/
  16.  
  17. /* system(...), timer(...), cls(...), gotoxy(...), 
  18. ** bdos(...), peek(...), poke(...)
  19. */
  20.  
  21. #include "systems.h"
  22. #include "types.h"
  23. #include "atoms.h"
  24. #include "errors.h"
  25. #include "files.h"
  26.  
  27. /*
  28. EXPORT long TIMER();
  29. EXPORT boolean FileExist();
  30. EXPORT void DOCLS(),DOGOTOXY();
  31. EXPORT boolean call_system(char *);
  32. */
  33.  
  34. IMPORT void TESTATOM(),ARGERROR();
  35.  
  36. #if !CPM
  37. boolean call_system(char *command)
  38. #undef system  /* to avoid clash between macro definitions and clib */
  39.     int system();       /* from clib */
  40. #if UNIX 
  41.   return (system(command) !=127); 
  42. #endif
  43. #if RISCOS 
  44.   return (system(command) == 0); 
  45. #endif
  46. #if MS_DOS 
  47.   return (system(command)==0); 
  48. #endif
  49. #if VMS
  50.   return (system(command) !=0); 
  51. #endif
  52. }
  53. #endif
  54.  
  55. #if RISCOS
  56. IMPORT long  clock();  /* From CLIB */
  57. #endif
  58.  
  59. GLOBAL long TIMER(void)
  60. /* returns the current system timer normalized to 1/100 sec. */
  61. {
  62. #if UNIX || VMS
  63.  static struct 
  64.      { long usertime,systime,cusertime,csystime; } UTIME;
  65.   long T;
  66.   IMPORT long times(); /* from clib */
  67.   (void)times(&UTIME);   
  68. #endif
  69. #if XENIX286
  70.   return UTIME.usertime*2l;
  71. #endif
  72. #if UNIX && !XENIX286
  73.   T=UTIME.usertime*5l;
  74.   return T/3l; 
  75. #endif
  76.  
  77. #if RISCOS
  78.   return  clock();
  79. #endif
  80.  
  81. #if VMS
  82.   return  UTIME.usertime;
  83. #endif
  84.  
  85. #if MS_DOS 
  86.   static union {long far *ptr; struct {unsigned off,seg; }ibm; }trans;
  87.   long T;
  88.   trans.ibm.seg=0; trans.ibm.off=0x46c; 
  89.   T= *(trans.ptr);
  90.   T=T*55l;
  91.   return T/10l;
  92. #endif
  93.  
  94. #if BIC
  95.   long T;
  96.   T=(long)(*((int *)(0xfc0c)));
  97.   return T+T;
  98. #endif
  99. }
  100.  
  101. GLOBAL boolean FileExist(char *filename)
  102. {
  103. #if UNIX || MS_DOS || VMS 
  104.     extern int access(); /* from clib UNIX, MS_DOS ,VMS */   
  105.     return (access(filename,0)==0) ;
  106. #endif
  107. #if !(UNIX || MS_DOS || VMS)
  108.     int f;
  109.     if((f=open(filename,0))>=0) { close(f); return true; }
  110.     return false;
  111. #endif
  112. }
  113.  
  114.  
  115.  
  116. GLOBAL char *s_cls(void)
  117. #if P8000
  118.     static char ss[]="\033*\036";
  119.     return ss;
  120. #endif
  121. #if VMS || MS_DOS || XENIX286 || SUN3
  122.     static char ss[]="\033[2J\033[0;0H";
  123.     return ss;
  124. #endif
  125. #if CPM
  126.     static char ss[]="\014";
  127.     return ss;
  128. #endif
  129. }
  130.  
  131. GLOBAL char *s_gotoxy(int S, int Z)
  132. #if P8000 
  133.    static char ss[]= "\033=ZS";
  134.    ss[2]=Z+32;ss[3]=S+32;
  135.    return ss;
  136. #endif
  137. #if VMS || MS_DOS || XENIX286 || SUN3
  138.    static char ss[]="\033[YY;XXH";
  139.    ss[2]= (char)(Z / 10) + '0';
  140.    ss[3]= (char)(Z % 10) + '0';
  141.    ss[5]= (char)(S / 10) + '0';
  142.    ss[6]= (char)(S % 10) + '0';
  143.    return ss;
  144. #endif
  145. #if CPM 
  146.    static char ss[]= "\033ZS";
  147.    ss[1]=Z+128;ss[2]=S+128;
  148.    return ss;
  149. #endif
  150. }
  151.    
  152. #if  CPM || HACKY
  153.  
  154. extern TERM A0,A1,A2;
  155.  
  156. GLOBAL boolean DOPOKE(void)
  157. { TERM T;
  158.   char *addr;
  159.   if(name(A0)!=INTT) ARGERROR();
  160.   addr=(char *)ival(A0);
  161.   T=A1;
  162.   while(name(T)==CONS_2)
  163.     { *addr++= (char)(INTVALUE(arg1(T))&0xff); T=arg2(T); }
  164.   TESTATOM(NIL_0,T);
  165.   return true;
  166. }
  167.  
  168. GLOBAL boolean DOPEEK(void)
  169. { TERM T,TT;
  170.   int i;
  171.   char *addr;
  172.   addr=(char *)INTVALUE(A0);
  173.   i=INTVALUE(A1);
  174.   T=TT=mkatom(NIL_0);
  175.   while(i-- >0)
  176.   { name(TT)=CONS_2;
  177.     son(TT)=mk2sons(INTT,(TERM)(*addr++),NIL_0,nil_term);  
  178.     TT=br(son(TT)); 
  179.   }
  180.   return UNI(A2,T); 
  181. }
  182.  
  183. #endif
  184.  
  185.